﻿@model Huirui.Cavan.Presentation.ViewModel.SystemModule.IAccountViewModel
@{Layout = null;}
@using (Html.BeginForm(ActionConst.INITIAL, ControllerConst.ACCOUNT))
{  
    <div class="tool_bar">
        <input id="accountInitial_save" type="submit" style="display: none;" />
        <a href="#" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-save'"
            onclick="javascript:$('#accountInitial_save').click()">保存</a>
        <input id="accountInitial_edit" type="button" style="display: none;" />
        <a href="#" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-undo'"
            onclick="javascript:$('#accountInitial_edit').click()">编辑</a>
        <a href="#" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-collapse'"
            onclick="toggleHeard()">折叠/展开</a>
    </div>
}
<table id="accountinitial">
</table>
<script type="text/javascript">
    $(function () {
        $('#accountinitial').datagrid({
            class: 'easyui-datagrid',
            singleSelect: true,
            idField: 'Id',
            url: '/account/list',
            columns: [[
                    { field: 'Id', title: '账户编码', width: 60 },
                    { field: 'Name', title: '名称', width: 100 },
                    { field: 'Currency', title: '币别', width: 100 },
                    {
                        field: 'InitialDate', title: '初始日期', width: 150, editor: {
                            type: 'datebox',
                            options: {
                                required: true
                            }
                        }
                    },
                    { field: 'InitialAmount', title: '初始余额', width: 80, align: 'right', editor: 'numberbox' }
            ]],
            onLoadSuccess: function (data) {
                var rows = $('#accountinitial').datagrid('getRows');
                for (var i = 0; i < rows.length; i++) {
                    $('#accountinitial').datagrid('beginEdit', i);
                }
            }
        });

        $("form[action^='/account/initial']").submit(function () {
            endEdit();
            if ($('#accountinitial').datagrid('getChanges').length) {
                var updated = $('#accountinitial').datagrid('getChanges', 'updated');

                var effectRow = new Object();
                if (updated.length) {
                    effectRow["updated"] = JSON.stringify(updated);
                }

                $.post("/account/initial", effectRow, function (data) {
                    if (data.IsSuccess) {
                        $.messager.alert("提示", data.Messages[0]);
                    }
                }, "JSON").error(function () {
                    $.messager.alert("提示", "网络异常，请稍候再试");
                });
            }

            return false;
        });

        function endEdit() {
            var rows = $('#accountinitial').datagrid('getRows');
            for (var i = 0; i < rows.length; i++) {
                $('#accountinitial').datagrid('endEdit', i);
            }
        }

        $('#accountInitial_edit').bind('click', function () {
            var rows = $('#accountinitial').datagrid('getRows');
            for (var i = 0; i < rows.length; i++) {
                $('#accountinitial').datagrid('beginEdit', i);
            }
        })
    });
</script>
